package com.example.WeChat.Data.Mapper;


import com.example.WeChat.Entity.User;
import org.apache.ibatis.annotations.*;
/*
*   mybatis mapper映射
*/

@Mapper
public interface UserMapper {
    //登录
    @Select("select * from login_credentials where username = #{user} and password_hash = #{passwordHash}")
    Integer login(String user,String passwordHash);
    //获取个人信息
    @Select("select * from users where user_id = ${userid}")
    User user(Long userid);
    //获取自己好友的数量
    @Select("select count(*) from friends where user_id = #{userId}")
    int friendCount(Long userId);
    //添加好友
    @Insert("insert into friends(user_id,friend_id) values(#{userId},#{friendId})")
    void addFriend(Long userId,Long friendId);
    //注册账号
    @Insert("insert into login_credentials(username, password_hash) values(#{username},#{passwordHash})")
    void register(String username, String passwordHash);
    //修改个人信息
    @Update("update users set username = #{user.userName},email = #{user.email},phone = #{user.phone},avatar_url=#{user.avatarUrl} where user_id = #{id}")
    void update(User user,Long userId);
    //提交个人信息
    @Results({
            @Result(property = "userName", column = "username"),
            @Result(property = "avatarUrl", column = "avatar_url"),
            @Result(property = "registrationDate", column = "registration_date")
    })
    @Insert("insert into users(user_id,username, email, phone, avatar_url, registration_date) values (#{user.userId},#{user.userName},#{user.email},#{user.phone},#{user.avatarUrl},#{user.registrationDate})")
    void submitUser(User user);
    //注销
}
